from rest_framework import serializers

from news.models import News, NewsCategory


class NewsSlideSerializer(serializers.ModelSerializer):
    # 轮播图新闻序列化器
    class Meta:
        model = News
        fields = ('title', 'img_url')


class NewsTopSerializer(serializers.ModelSerializer):
    # 推荐新闻序列化器
    class Meta:
        model = News
        fields = ('title', 'create_time')


class NewsImageSerializer(serializers.ModelSerializer):
    # 图片新闻序列化器
    class Meta:
        model = News
        fields = ('title', 'img_url', 'create_time')


class OneNewsCategoryAlbumSerializer(serializers.ModelSerializer):
    """一级新闻分类图片序列化器"""

    class Meta:
        # model 指明要序列化的模型类
        model = NewsCategory
        fields = ('id', 'title')


# 备注序列化器优化，嵌套使用
class TwoNewsCategoryAlbumSerializer(serializers.ModelSerializer):
    """二级新闻分类图片序列化器"""

    class Meta:
        # model 指明要序列化的模型类
        model = News
        fields = ('title', 'create_time', 'img_url', 'zhaiyao')
